package com.hmy.finance.manager.fulfillment;


import cn.hutool.json.JSONUtil;
import com.hmy.ccp.common.result.FeignResult;
import com.hmy.ccp.error.exception.HMYRuntimeException;
import com.hmy.fulfillment.api.bo.request.CountUnFinishClaimRequest;
import com.hmy.fulfillment.api.bo.request.CountUnFinishPauseRequest;
import com.hmy.fulfillment.api.bo.request.ExitingFormCountRequest;
import com.hmy.fulfillment.api.bo.response.ExitingFormCountResponse;
import com.hmy.fulfillment.api.client.ClaimFeignClient;
import com.hmy.fulfillment.api.client.ExitFormFeignClient;
import com.hmy.fulfillment.api.client.PauseFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Objects;

@Component
@Slf4j
public class FulfillmentFeignClientRpc {

    @Resource
    private ClaimFeignClient claimFeignClient;

    @Resource
    private PauseFeignClient pauseFeignClient;

    @Resource
    private ExitFormFeignClient exitFormFeignClient;


    public Integer getClaimCountByCustomerInfo(CountUnFinishClaimRequest request) {
        FeignResult<Integer> response = null;
        log.info("FulfillmentFeignClientRpc.getClaimInforsByCustomerInfo params:{}", JSONUtil.toJsonPrettyStr(request));
        response = claimFeignClient.countUnFinishClaim(request);
        if (Objects.isNull(response)) {
            throw new HMYRuntimeException(506300003);
        }
        if (response.isFailed()) {
            throw new HMYRuntimeException(response.getMsgCode(), response.getErrorText());
        }
        return response.getData();
    }

    public Integer getPauseCountByCustomerInfo(CountUnFinishPauseRequest request) {
        FeignResult<Integer> response;
        log.info("FulfillmentFeignClientRpc.getPauseCountByCustomerInfo params:{}", JSONUtil.toJsonPrettyStr(request));
        response = pauseFeignClient.countUnFinishPause(request);
        if (Objects.isNull(response)) {
            throw new HMYRuntimeException(506300005);
        }
        if (response.isFailed()) {
            throw new HMYRuntimeException(response.getMsgCode(), response.getErrorText());
        }
        return response.getData();
    }

    public ExitingFormCountResponse queryExitingFormCount(ExitingFormCountRequest request) {
        FeignResult<ExitingFormCountResponse> response;
        log.info("exitFormFeignClient.queryExitingFormCountByOrderId params:{}", JSONUtil.toJsonPrettyStr(request));
        response = exitFormFeignClient.queryExitingFormCount(request);
        if (Objects.isNull(response)) {
            throw new HMYRuntimeException(506300005);
        }
        if (response.isFailed()) {
            throw new HMYRuntimeException(response.getMsgCode(), response.getErrorText());
        }
        return response.getData();
    }


}
